<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_CodeFunc.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>선별결과등록하기</title>
<link href="../css/layout.css" type="text/css" rel="stylesheet" />
<link type="text/css" href="/css/hot-sneaks/jquery-ui-1.8.18.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
$(function(){
	// Datepicker
	$('#r_product_date').datepicker({
		inline: true,
		showOn: 'button',
		buttonImage:"/img/ico_cal.jpg",
		buttonImageOnly: true
	});
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
});
</script>
<script type="text/javascript">
	function value_check()
	{
		if (!isEmpty($('#r_product_date')))
		{
			alert("선별일을 입력하세요");
			$('#r_product_date').focus();
			return;
		}
		if (!isEmpty($('#r_product_grade2')))
		{
			alert("등급을 선택하세요");
			$('#r_product_grade2').focus();
			return;
		}
		if (!isEmpty($('#r_product_standard2')))
		{
			alert("규격을 선택하세요");
			$('#r_product_standard2').focus();
			return;
		}
		if (!isEmpty($('#r_product_weight2')))
		{
			alert("중량 선택하세요");
			$('#r_product_weight2').focus();
			return;
		}
		if (!isEmpty($('#r_product_number')))
		{
			alert("수량을 입력하세요");
			$('#r_product_number').focus();
			return;
		}
		if (!isNumber($('#r_product_number')))
		{
			alert("수량은 숫자만 입력하세요");
			$('#r_product_number').val("");
			$('#r_product_number').focus();
			return;
		}
		if ($('#r_product_number').val()<=0)
		{
			alert("수량은 0보다 큰수를 입력하세요");
			$('#r_product_number').val("");
			$('#r_product_number').focus();
			return;
		}
		if ($('#r_product_loss').val()=="")
		{
			$('#r_product_loss').val(0);
		}
		if (!isNumber($('#r_product_loss')))
		{
			alert("감모량은 숫자만 입력하세요");
			$('#r_product_loss').val("");
			$('#r_product_loss').focus();
			return;
		}
		if ($('#r_product_loss').val()<0)
		{
			alert("감모량은 0보다 큰수를 입력하세요");
			$('#r_product_loss').val("");
			$('#r_product_loss').focus();
			return;
		}
		$('#r_product_total').val(($('#r_product_weight2').val()*$('#r_product_number').val())+Number($('#r_product_loss').val()));
		if (Number($('#rtotal').val())+Number($('#r_product_total').val())>Number($('#pototal').val()))
		{
			alert("선별량이 원물의 총중량보다 많습니다.\n다시입력해주세요.");
			return;
		}
		document.theForm.target="if_nvl";
		document.theForm.submit();
	}
	function totalinput()
	{
		if ($('#r_product_number').val()!="" && !isNumber($('#r_product_number')))
		{
			alert("수량은 숫자만 입력하세요");
			$('#r_product_number').val("");
			$('#r_product_number').focus();
			return;
		}
		if ($('#r_product_loss').val()!="" && !isNumber($('#r_product_loss')))
		{
			alert("감모량은 숫자만 입력하세요");
			$('#r_product_loss').val("");
			$('#r_product_loss').focus();
			return;
		}
		if ($('#r_product_weight2').val()!="")
		{
			var inisum = $('#r_product_weight2').val()*$('#r_product_number').val();

			if ($('#r_product_loss').val()!="")
			{
				inisum += Number($('#r_product_loss').val());
			}
			var html = $("#sum").html();
			html = inisum +"KG";
			$("#sum").html(html);
			$("#r_product_total").val(inisum);
			return;
		}
	}
	function totalinput2()
	{
		if ($('#r_product_number').val()!="" && isNumber($('#r_product_number')) && $('#r_product_weight2').val()!="")
		{
			var inisum = $('#r_product_weight2').val()*$('#r_product_number').val();
			if ($('#r_product_loss').val()!="")
			{
				inisum += Number($('#r_product_loss').val());
			}
			var html = $("#sum").html();
			html = inisum +"KG";
			$("#sum").html(html);
			$("#t_product_total").val(inisum);
			return;
		}
	}
	function fnview(seq2)
	{
		location="item_manage_sort_write.html?menu1=<?=$menu1?>&menu2=<?=$menu2?>&seq=<?=$seq?>&seq2="+seq2;
	}
	function cancle_check()
	{
		location="item_manage_sort_write.html?menu1=<?=$menu1?>&menu2=<?=$menu2?>&seq=<?=$seq?>";
	}
	function input_check()
	{
		document.theForm.mode.value="w";
		value_check();
	}
	function update_check()
	{
		document.theForm.mode.value="u";
		value_check();
	}
	function delete_check()
	{
		if(confirm("삭제하시겠습니까?"))
		{
			document.theForm.mode.value="d";
			document.theForm.target="if_nvl";
			document.theForm.submit();
		}
	}
	function fnlist()
	{
		location="item_manage_sort_write.html?menu1=<?=$menu1?>&menu2=<?=$menu2?>&seq=<?=$seq?>";
	}

	$(document).ready(function(){
		totalinput2();
	});
</script>
</head>
<body class="pop">
<!-- view start -->
<? include("./item_manage_sort_write_view.php"); ?>
<!-- view end -->
<div class="manage_sorttitle"><span>선별결과등록하기</span></div>
	<div class="memoplace">
			<div class="tableTitle"><span class="b"></span>[선별] 결과 등록</div>
			<form name="theForm" method="post" action="./item_manage_sort_write_proc.php">
			<input type="hidden" name="mode" id="mode" />
			<input type="hidden" name="menu1" id="menu1" value="<?=$menu1?>" />
			<input type="hidden" name="menu2" id="menu2" value="<?=$menu2?>" />
			<input type="hidden" name="seq" id="seq" value="<?=$seq?>" />
			<input type="hidden" name="seq2" id="seq2" value="<?=$seq2?>" />
			<input type="hidden" name="pototal" id="pototal" value="<?=$pototal?>" />
			<table cellpadding="0" cellspacing="1" border="0" class="erpTable">
			<colgroup>
				<col width="80px" />
				<col width="*" />
				<col width="80px" />
				<col width="*" />
				<col width="80px" />
				<col width="*" />
				<col width="80px" />
				<col width="*" />
			</colgroup>
				<tr>
					<th>농협명</th>
					<td><?=$jname?></td>
					<th>생산자</th>
					<td><?=$fname?></td>
					<th>품목</th>
					<td><?=$poitem1?></td>
					<th>품종</th>
					<td><?=$poitem2?></td>
					<th>중량</th>
					<td><span class="weight"><?=$pototal?>kg</span></td><!-- 하단 등록테이블에서 수량을 입력하면 자동으로 차감 되게끔 -->
				</tr>
			</table>
            <table cellpadding="0" cellspacing="1" border="0" class="erpTable">
            	<tr>
                    <th>선별일자</th>
					 <th>원산지</th>
					 <th>등급</th>
					 <th>규격</th>
					 <th>중량</th>
					 <th>수량</th>
					 <th>감모량</th>
					 <th>합계</th>
				</tr>
				<tr>
					<td class="day_cal">
                    	<input type="text" id="r_product_date" value="<?=$ndate?>" name="r_product_date" title="선별일입력/달력을클릭해주세요." readonly class="boxinput w65" style="margin-right:2px;vertical-align:top;" />
					</td>
					<td>
						<input type="text" name="r_product_country" id="r_product_country" value="<?=$ocountry?>" class="boxinput w50" />
					</td>

					<td>
						<input type="hidden" name="r_product_grade1" id="r_product_grade1" value="2" />
                    	<select name="r_product_grade2" id="r_product_grade2">
                        	<option value="">등급</option>
							<?
								$codedata = & Code_GetSelect("B", 2, 2);
								Code_PrintOption($codedata, 2, $ograde2);
							?>
                        </select>
					</td>

					<td>
						<input type="hidden" name="r_product_standard1" id="r_product_standard1" value="3" />
                    	<select name="r_product_standard2" id="r_product_standard2">
                        	<option value="">규격</option>
							<?
								$codedata = & Code_GetSelect("B", 2, 3);
								Code_PrintOption($codedata, 2, $ostandard2);
							?>
                        </select>
					</td>

					<td>
						<input type="hidden" name="r_product_weight1" id="r_product_weight1" value="1" />
                    	<select name="r_product_weight2" id="r_product_weight2" onchange="totalinput2();">
                        	<option value="">중량</option>
							<?
								$codedata = & Code_GetSelect("B", 2, 1);
								Code_PrintOption($codedata, 2, $oweight2, "KG");
							?>
                        </select>
					</td>

					<td><input type="text" id="r_product_number" name="r_product_number" onblur="totalinput();" value="<?=$onumber?>" title="수량" class="boxinput w30" /></td>

					<td><input type="text" id="r_product_loss" name="r_product_loss" onblur="totalinput2();" value="<?=$oloss?>" title="감모량" class="boxinput w50" /></td>

					<td><span id="sum"></span></td>
				</tr>
            </table>
            <div class="BtnList">
            	<ul>
				<?if ($seq2==""){?>
                  	<li><input type="button" class="btn_submit" title="등록" onclick="input_check();" /></li>
				<?}else{?>
					<li><input type="button" class="btn_modify" title="수정" onclick="update_check();"/></li>
                    <li><input type="button" class="btn_del" title="삭제" onclick="delete_check();"/></li>
					<li><input type="button" class="btn_cancel" title="취소" onclick="cancle_check();"/></li>
				<?}?>
                </ul>
            </div>
			<input type="hidden" name="r_product_total" id="r_product_total" value="<?=$ototal?>" />
			</form>
			<!-- 선별등록된 리스트 출력 및 리스트 중 항목 선택하여 수정 및 삭제 / 인쇄가 가능 -->
			<div class="tableTitle"><span class="b"></span>[선별] 결과 목록</div>
			<div class="listframe">
            <table cellpadding="0" cellspacing="1" border="0" class="erpTable">
				<colgroup>
				<col width="3%" />
				</colgroup>
            	<tr>
					<th><input type="checkbox" id="" title="전체삭제" /></th>
                	<th>선별일시</th>
                    <th>농협명</th>
                    <th>생산자</th>
                    <th>원산지</th>
                    <th>품목</th>
					<th>품종</th>
					<th>등급</th>
					<th>규격</th>
					<th>중량</th>
					<th>감모량</th>
					<th>수량</th>
					<th>합계</th>
					<th>선별확인증</th>
				</tr>
<!-- list start -->
<? include("./item_manage_sort_write_list.php"); ?>
<!-- list end -->
            </table>
			</div>
	</div>
<input type="hidden" name="rtotal" id="rtotal" value="<?=$rtotal?>" />
<iframe name=if_nvl id=if_nvl src='' style='display:none'></iframe>
</body>
</html>
